#include <map>
#include "DeferredRenderSystem.h"
#include "EngineProfileSample.h"
#include "ObjFunctor.h"
#include "EngineMessages.h"
#include "EngineLog.h"
#include "HardwareSystemMessages.h"
#include "resource.h"

DeferredRenderSystem::DeferredRenderSystem(EnginePointer<SettingsManager>& settings, EnginePointer<IMessageQueue>& messages)
:IEngineSystem(settings, messages)
{
	initialized = FALSE;
	graphicsLoaded = FALSE;

	contentModule = NULL;
	hardwareSystem = NULL;
	pDevice = NULL;
	pSwapChain = NULL;
	pCommonPool = NULL;
	pViewProjVariable = NULL;
	pCameraPositionVariable = NULL;
	pInverseViewProjVariable = NULL;
	pDiffuseVariable = NULL;
	pNormalVariable = NULL;
	pDepthVariable = NULL;
	pDiffuseLightVariable = NULL;
	pSpecularLightVariable = NULL;
	pFinalTargetView = NULL;
	pLightTargetViews[0] = NULL;
	pLightTargetViews[1] = NULL;
	pObjectTargetViews[0] = NULL;
	pObjectTargetViews[1] = NULL;
	pDiffuseView = NULL;
	pNormalView = NULL;
	pDiffuseLightView = NULL;
	pDepthView = NULL;
	pObjectStencilView = NULL;
	pDisabledStencilState = NULL;
	pLightBlendState = NULL;
	currentCamera = NULL;

	pModelLoader = new ModelLoader();
}

DeferredRenderSystem::~DeferredRenderSystem(void)
{
	pModelLoader = NULL;

	UnloadGraphicsContent();

	modelComponents.clear();
	models.clear();
	guiComponents.clear();
	

	hardwareSystem = NULL;
	contentModule = NULL;
}

void DeferredRenderSystem::UnloadGraphicsContent()
{
	if (contentModule != NULL) FreeLibrary(contentModule);
	contentModule = NULL;

	if (graphicsLoaded)
	{
		ID3D10Buffer* emptyBuffer[1] = {NULL};
		UINT emptyInts[1] = {0};
		ID3D10ShaderResourceView* emptyResources[1] = {0};
		ID3D10SamplerState* emptySamplers[1] = {0};
		pDevice->IASetIndexBuffer(NULL, DXGI_FORMAT_R16_UINT, 0);
		pDevice->VSSetShader(NULL);
		pDevice->GSSetShader(NULL);
		pDevice->PSSetShader(NULL);
		pDevice->GSSetConstantBuffers(0, 1, emptyBuffer);
		pDevice->IASetVertexBuffers(0, 1, emptyBuffer, emptyInts, emptyInts);
		pDevice->PSSetShaderResources(0, 1, emptyResources);
		pDevice->PSSetShaderResources(1, 1, emptyResources);
		pDevice->PSSetShaderResources(2, 1, emptyResources);
		pDevice->PSSetSamplers(0, 1, emptySamplers);
		pDevice->OMSetBlendState(NULL, 0, 0xFFFFFFFF);
		pDevice->OMSetDepthStencilState(NULL, 0);
		pDevice->IASetInputLayout(NULL);
		pDevice->OMSetRenderTargets(0, NULL, NULL);

		finalRenderer.UnloadGraphicsContent();
		pointRenderer.UnloadGraphicsContent();
		spotRenderer.UnloadGraphicsContent();
		ambientRenderer.UnloadGraphicsContent();
		directionalRenderer.UnloadGraphicsContent();
		objectRenderer.UnloadGraphicsContent();

		pDepthVariable = NULL;
		pNormalVariable = NULL;
		pDiffuseVariable = NULL;
		pDiffuseLightVariable = NULL;
		pSpecularLightVariable = NULL;
		pInverseViewProjVariable = NULL;
		pCameraPositionVariable = NULL;
		pViewProjVariable = NULL;
		pCommonPool = NULL;

		for (set<EnginePointer<Model>>::iterator it = models.begin(); it != models.end(); it++)
		{
			(*it)->UnloadGraphicsContent();
		}

		for (list<EnginePointer<GUIComponent>>::iterator it = guiComponents.begin(); it != guiComponents.end(); it++)
		{
			(*it)->UnloadGraphicsContent();
		}
	}

	graphicsLoaded = false;

	UnloadResourceContent();
}

void DeferredRenderSystem::UnloadResourceContent()
{
	if (pDevice.isValid()) pDevice->OMSetRenderTargets(0, NULL, NULL);

	if (pLightBlendState != NULL) pLightBlendState->Release();
	pLightBlendState = NULL;
	if (pDisabledStencilState != NULL) pDisabledStencilState->Release();
	pDisabledStencilState = NULL;
	if (pObjectStencilView != NULL) pObjectStencilView->Release();
	pObjectStencilView = NULL;
	if (pDepthView != NULL) pDepthView->Release();
	pDepthView = NULL;
	if (pDiffuseLightView!= NULL) pDiffuseLightView->Release();
	pDiffuseLightView = NULL;
	if (pNormalView!= NULL) pNormalView->Release();
	pNormalView = NULL;
	if (pDiffuseView!= NULL) pDiffuseView->Release();
	pDiffuseView = NULL;
	if (pObjectTargetViews[0] != NULL) pObjectTargetViews[0]->Release();
	pObjectTargetViews[0] = NULL;
	if (pObjectTargetViews[1] != NULL) pObjectTargetViews[1]->Release();
	pObjectTargetViews[1] = NULL;
	if (pLightTargetViews[0] != NULL) pLightTargetViews[0]->Release();
	pLightTargetViews[0] = NULL;
	if (pLightTargetViews[1] != NULL) pLightTargetViews[1]->Release();
	pLightTargetViews[1] = NULL;
	if (pFinalTargetView != NULL) pFinalTargetView->Release();
	pFinalTargetView = NULL;
	pSwapChain = NULL;
	pDevice = NULL;

	initialized = FALSE;
}

HRESULT DeferredRenderSystem::LoadGraphicsContent()
{
	HRESULT hr;
	
	hr = LoadResourceContent();
	if (FAILED(hr)) return hr;

	for (set<EnginePointer<Model>>::iterator it = models.begin(); it != models.end(); it++)
	{
		hr = (*it)->LoadGraphicsContent(pDevice);
		if (FAILED(hr)) return hr;
	}
	
	for (list<EnginePointer<GUIComponent>>::iterator it = guiComponents.begin(); it != guiComponents.end(); it++)
	{
		hr = (*it)->LoadGraphicsContent(pDevice);
		if (FAILED(hr)) return hr;
	}

	contentModule = LoadLibrary(L"D3D10EngineContent.dll");
	if (contentModule == NULL) return E_FAIL;

#ifdef _DEBUG
	hr = D3DX10CreateEffectPoolFromResource(contentModule, MAKEINTRESOURCE(COMMON_EFFECT), NULL, NULL, NULL, "fx_4_0", D3D10_SHADER_ENABLE_STRICTNESS | D3D10_SHADER_DEBUG, 0, pDevice, NULL, pCommonPool.innerAddress(), NULL, NULL);
#else
	hr = D3DX10CreateEffectPoolFromResource(contentModule, MAKEINTRESOURCE(COMMON_EFFECT), NULL, NULL, NULL, "fx_4_0", D3D10_SHADER_ENABLE_STRICTNESS, 0, pDevice, NULL, pCommonPool.innerAddress(), NULL, NULL);
#endif
	if (FAILED(hr)) return hr;

	ID3D10Effect* commonEffect = pCommonPool->AsEffect();
	pViewProjVariable = commonEffect->GetVariableByName("ViewProj")->AsMatrix();
	pCameraPositionVariable = commonEffect->GetVariableByName("CameraPosition")->AsVector();
	pInverseViewProjVariable = commonEffect->GetVariableByName("InverseViewProj")->AsMatrix();
	pDiffuseVariable = commonEffect->GetVariableByName("Diffuse")->AsShaderResource();
	pNormalVariable = commonEffect->GetVariableByName("Normal")->AsShaderResource();
	pDepthVariable = commonEffect->GetVariableByName("Depth")->AsShaderResource();
	pDiffuseLightVariable = commonEffect->GetVariableByName("DiffuseLight")->AsShaderResource();
	pSpecularLightVariable = commonEffect->GetVariableByName("SpecularLight")->AsShaderResource();

	hr = objectRenderer.LoadGraphicsContent(pDevice, pCommonPool);
	if (FAILED(hr)) return hr;

	hr = directionalRenderer.LoadGraphicsContent(pDevice, pCommonPool);
	if (FAILED(hr)) return hr;

	hr = ambientRenderer.LoadGraphicsContent(pDevice, pCommonPool);
	if (FAILED(hr)) return hr;

	hr = spotRenderer.LoadGraphicsContent(pModelLoader, pDevice, pCommonPool);
	if (FAILED(hr)) return hr;

	hr = pointRenderer.LoadGraphicsContent(pModelLoader, pDevice, pCommonPool);
	if (FAILED(hr)) return hr;

	hr = finalRenderer.LoadGraphicsContent(pDevice, pCommonPool);
	if (FAILED(hr)) return hr;

	initialized = TRUE;
	graphicsLoaded = TRUE;

	return S_OK;
}

HRESULT DeferredRenderSystem::LoadResourceContent()
{
	HRESULT hr;

	if (hardwareSystem.isValid())
	{
		pDevice = hardwareSystem->GetDevice();
		pSwapChain = hardwareSystem->GetSwapChain();
	}

	hr = this->InitializeRenderTargets();
	if (FAILED(hr)) return hr;

	hr = this->InitializeDepthBuffers();
	if (FAILED(hr)) return hr;

	hr = this->InitializeBlendStates();
	if (FAILED(hr)) return hr;

	hr = this->InitializeStencilStates();
	if (FAILED(hr)) return hr;

	return S_OK;
}

HRESULT DeferredRenderSystem::Initialize(EnginePointer<SystemCollection>& systems)
{
	HRESULT hr = S_OK;

	hardwareSystem = (EnginePointer<HardwareSystem>)systems->getSystem(HARDWARE_SYSTEM_GUID);
	if (hardwareSystem == NULL)
		return E_FAIL;

	sceneSystem = (EnginePointer<SceneSystem>)systems->getSystem(SCENE_SYSTEM_GUID);
	if (sceneSystem == NULL)
		return E_FAIL;

	for (list<EnginePointer<RenderComponent>>::iterator it = modelComponents.begin(); it != modelComponents.end(); it++)
	{
		hr = (*it)->LoadModel(pModelLoader);
		if (FAILED(hr)) return hr;

		EnginePointer<Model> model = (*it)->getModel();

		if (models.find(model) == models.end())
		{
			models.insert(model);
		}
	}

	return LoadGraphicsContent();
}

HRESULT DeferredRenderSystem::InitializeRenderTargets()
{
	HRESULT hr;
	D3D10_TEXTURE2D_DESC tDesc;
	D3D10_SHADER_RESOURCE_VIEW_DESC viewDesc;
	ID3D10Texture2D* texture = 0;

	hr = pSwapChain->GetBuffer(0, __uuidof(ID3D10Texture2D), (LPVOID*)&texture);
	if (FAILED(hr)) goto CLEAN;
	texture->GetDesc(&tDesc);
	hr = pDevice->CreateRenderTargetView(texture, NULL,& pFinalTargetView);
	if (FAILED(hr)) goto CLEAN;
	texture->Release();
	texture = 0;

	tDesc.BindFlags = D3D10_BIND_RENDER_TARGET | D3D10_BIND_SHADER_RESOURCE;
	
	tDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
	hr = pDevice->CreateTexture2D(&tDesc, NULL,& texture);
	if (FAILED(hr)) goto CLEAN;
	hr = pDevice->CreateRenderTargetView(texture, NULL,& pObjectTargetViews[0]);
	if (FAILED(hr)) goto CLEAN;
	viewDesc.ViewDimension = D3D10_SRV_DIMENSION_TEXTURE2D;
	viewDesc.Texture2D.MostDetailedMip = 0;
	viewDesc.Format = tDesc.Format;
	viewDesc.Texture2D.MipLevels = tDesc.MipLevels;
	pDevice->CreateShaderResourceView(texture,& viewDesc,& pDiffuseView);
	texture->Release();
	texture = 0;

	hr = pDevice->CreateTexture2D(&tDesc, NULL,& texture);
	if (FAILED(hr)) goto CLEAN;
	hr = pDevice->CreateRenderTargetView(texture, NULL,& pObjectTargetViews[1]);
	if (FAILED(hr)) goto CLEAN;
	viewDesc.ViewDimension = D3D10_SRV_DIMENSION_TEXTURE2D;
	viewDesc.Texture2D.MostDetailedMip = 0;
	viewDesc.Format = tDesc.Format;
	viewDesc.Texture2D.MipLevels = tDesc.MipLevels;
	pDevice->CreateShaderResourceView(texture,& viewDesc,& pNormalView);
	texture->Release();
	texture = 0;

	tDesc.Format = DXGI_FORMAT_R11G11B10_FLOAT;
	hr = pDevice->CreateTexture2D(&tDesc, NULL,& texture);
	if (FAILED(hr)) goto CLEAN;
	hr = pDevice->CreateRenderTargetView(texture, NULL,& pLightTargetViews[0]);
	if (FAILED(hr)) goto CLEAN;
	viewDesc.ViewDimension = D3D10_SRV_DIMENSION_TEXTURE2D;
	viewDesc.Texture2D.MostDetailedMip = 0;
	viewDesc.Format = tDesc.Format;
	viewDesc.Texture2D.MipLevels = tDesc.MipLevels;
	pDevice->CreateShaderResourceView(texture,& viewDesc,& pDiffuseLightView);
	texture->Release();
	texture = 0;

	tDesc.Format = DXGI_FORMAT_R16_FLOAT;
	hr = pDevice->CreateTexture2D(&tDesc, NULL,& texture);
	if (FAILED(hr)) goto CLEAN;
	hr = pDevice->CreateRenderTargetView(texture, NULL,& pLightTargetViews[1]);
	if (FAILED(hr)) goto CLEAN;
	viewDesc.ViewDimension = D3D10_SRV_DIMENSION_TEXTURE2D;
	viewDesc.Texture2D.MostDetailedMip = 0;
	viewDesc.Format = tDesc.Format;
	viewDesc.Texture2D.MipLevels = tDesc.MipLevels;
	pDevice->CreateShaderResourceView(texture,& viewDesc,& pSpecularLightView);
	texture->Release();
	texture = 0;

	D3D10_VIEWPORT vp;
	vp.Width = tDesc.Width;
	vp.Height = tDesc.Height;
	vp.MinDepth = 0.0f;
	vp.MaxDepth = 1.0f;
	vp.TopLeftX = 0;
	vp.TopLeftY = 0;
	pDevice->RSSetViewports(1,& vp);

	D3DXMatrixPerspectiveFovLH(&projection, (float)D3DX_PI / 3, (FLOAT)tDesc.Width / (FLOAT)tDesc.Width, 0.1f, 3000.0f );

	return S_OK;

CLEAN:

	if (texture != 0) texture->Release();
	return hr;
}

HRESULT DeferredRenderSystem::InitializeDepthBuffers()
{
	ID3D10Texture2D* texture = 0;
	UINT width, height;
	HRESULT hr;
	D3D10_SHADER_RESOURCE_VIEW_DESC viewDesc;

	D3D10_VIEWPORT vp;
	UINT numOfViewports = 1;
	pDevice->RSGetViewports(&numOfViewports,& vp);

	width = vp.Width;
	height = vp.Height;

	D3D10_TEXTURE2D_DESC descDepth;
	descDepth.Width = width;
	descDepth.Height = height;
	descDepth.MipLevels = 1;
	descDepth.ArraySize = 1;
	descDepth.Format = DXGI_FORMAT_R16_TYPELESS;
	descDepth.SampleDesc.Count = 1;
	descDepth.SampleDesc.Quality = 0;
	descDepth.Usage = D3D10_USAGE_DEFAULT;
	descDepth.BindFlags = D3D10_BIND_DEPTH_STENCIL | D3D10_BIND_SHADER_RESOURCE;
	descDepth.CPUAccessFlags = 0;
	descDepth.MiscFlags = 0;
	D3D10_DEPTH_STENCIL_VIEW_DESC descDSV;
	descDSV.Format = DXGI_FORMAT_D16_UNORM;
	descDSV.ViewDimension = D3D10_DSV_DIMENSION_TEXTURE2D;
	descDSV.Texture2D.MipSlice = 0;

	hr = pDevice->CreateTexture2D(&descDepth, NULL,& texture);
	if (FAILED(hr)) goto CLEAN;

	hr = pDevice->CreateDepthStencilView(texture,& descDSV,& pObjectStencilView);
	if (FAILED(hr)) goto CLEAN;

	viewDesc.ViewDimension = D3D10_SRV_DIMENSION_TEXTURE2D;
	viewDesc.Texture2D.MostDetailedMip = 0;
	viewDesc.Format = DXGI_FORMAT_R16_FLOAT;
	viewDesc.Texture2D.MipLevels = 1;
	hr = pDevice->CreateShaderResourceView(texture, &viewDesc, &pDepthView);
	if (FAILED(hr)) goto CLEAN;

CLEAN:
	if (texture != 0) texture->Release();

	if (FAILED(hr)) return hr;

	return S_OK;
}

HRESULT DeferredRenderSystem::InitializeStencilStates()
{
	HRESULT hr = S_OK;

	D3D10_DEPTH_STENCIL_DESC depthDesc;
	ZeroMemory(&depthDesc, sizeof(D3D10_DEPTH_STENCIL_DESC));

	hr = pDevice->CreateDepthStencilState(&depthDesc,& pDisabledStencilState);
	if (FAILED(hr)) return hr;

	return hr;
}

HRESULT DeferredRenderSystem::InitializeBlendStates()
{
	HRESULT hr;
	D3D10_BLEND_DESC desc;
	ZeroMemory(&desc, sizeof(D3D10_BLEND_DESC));

	desc.BlendEnable[0] = TRUE;
	desc.BlendEnable[1] = TRUE;
	desc.SrcBlend = D3D10_BLEND_ONE;
	desc.DestBlend = D3D10_BLEND_ONE;
	desc.BlendOp = D3D10_BLEND_OP_ADD;
	desc.SrcBlendAlpha = D3D10_BLEND_ONE;
	desc.DestBlendAlpha = D3D10_BLEND_ONE;
	desc.BlendOpAlpha = D3D10_BLEND_OP_ADD;
	desc.RenderTargetWriteMask[0] = D3D10_COLOR_WRITE_ENABLE_ALL;
	desc.RenderTargetWriteMask[1] = D3D10_COLOR_WRITE_ENABLE_ALL;

	hr = pDevice->CreateBlendState(&desc,& pLightBlendState);
	if (FAILED(hr)) return hr;

	return S_OK;
}

void DeferredRenderSystem::Update(LONGLONG timeElapsed)
{
	for (list<EnginePointer<GUIComponent>>::iterator it = guiComponents.begin(); it != guiComponents.end(); it++)
	{
		(*it)->Update(timeElapsed);
	}
	
	if (pDevice.isValid())
	{
		float ClearColor[4] = {0.0f, 0.0f, 0.0f, 0.0f};

		pDevice->ClearRenderTargetView(pFinalTargetView, ClearColor);
		pDevice->ClearRenderTargetView(pObjectTargetViews[0], ClearColor);
		pDevice->ClearRenderTargetView(pObjectTargetViews[1], ClearColor);
		pDevice->ClearRenderTargetView(pLightTargetViews[0], ClearColor);
		pDevice->ClearRenderTargetView(pLightTargetViews[1], ClearColor);
		pDevice->ClearDepthStencilView(pObjectStencilView, D3D10_CLEAR_DEPTH, 1.0f, 0);

		if (!currentCamera.isValid()) {
			currentCamera = (*sceneSystem->CamerasBegin());
		}

		if (currentCamera.isValid()) {
			
			ID3D10ShaderResourceView* nullShader = 0;
			pDevice->PSSetShaderResources(2, 1, &nullShader);
			pDevice->OMSetRenderTargets(2, pObjectTargetViews, pObjectStencilView);
			pDevice->OMSetBlendState(NULL, 0, 0xFFFFFFFF);
			pDevice->OMSetDepthStencilState(NULL, 0);
			pDevice->IASetPrimitiveTopology(D3D10_PRIMITIVE_TOPOLOGY_TRIANGLELIST);

			D3DXMATRIX ViewProjection = currentCamera->getView() * projection;
			pViewProjVariable->SetMatrix(ViewProjection);
			pCameraPositionVariable->SetFloatVector(currentCamera->getPosition());
			D3DXMATRIX viewProjInverse;
			D3DXMatrixInverse(&viewProjInverse, NULL, &ViewProjection);
			pInverseViewProjVariable->SetMatrix(viewProjInverse);

			map<EnginePointer<Model>, list<EnginePointer<RenderComponent>>> modelBatches;

			for (list<EnginePointer<RenderComponent>>::iterator it = modelComponents.begin(); it != modelComponents.end(); it++)
			{
				if (modelBatches.find((*it)->getModel()) == modelBatches.end())
				{
					modelBatches.insert(pair<EnginePointer<Model>, list<EnginePointer<RenderComponent>>>((*it)->getModel(), list<EnginePointer<RenderComponent>>()));
				}
				modelBatches[(*it)->getModel()].push_back(*it);
			}

			for (map<EnginePointer<Model>, list<EnginePointer<RenderComponent>>>::iterator it = modelBatches.begin(); it != modelBatches.end(); it++)
			{
				EnginePointer<Model> model = (*it).first;
				objectRenderer.Render(model, (*it).second);
			}

			pDevice->OMSetRenderTargets(2, pLightTargetViews, NULL);
			pDevice->OMSetBlendState(pLightBlendState, 0, 0xFFFFFFFF);
			pDevice->OMSetDepthStencilState(pDisabledStencilState, 0);

			pDiffuseVariable->SetResource(pDiffuseView);
			pDepthVariable->SetResource(pDepthView);
			pNormalVariable->SetResource(pNormalView);

			directionalRenderer.Render(sceneSystem->DirectionalComponentsBegin(), sceneSystem->DirectionalComponentsEnd());
			ambientRenderer.Render(sceneSystem->AmbientComponentsBegin(), sceneSystem->AmbientComponentsEnd());
			pointRenderer.Render(sceneSystem->PointComponentsBegin(), sceneSystem->PointComponentsEnd());
			spotRenderer.Render(sceneSystem->SpotComponentsBegin(), sceneSystem->SpotComponentsEnd());

			pDevice->OMSetRenderTargets(1, &pFinalTargetView, NULL);

			pDiffuseLightVariable->SetResource(pDiffuseLightView);
			pSpecularLightVariable->SetResource(pSpecularLightView);

			finalRenderer.Render();
		}

		if (currentCamera == NULL)
		{
			pDevice->OMSetRenderTargets(1,& pFinalTargetView, NULL);
		}

		for (list<EnginePointer<GUIComponent>>::iterator it = guiComponents.begin(); it != guiComponents.end(); it++)
		{
			(*it)->Draw();
		}

		pSwapChain->Present(0, 0);
	}
}

void DeferredRenderSystem::DeliverMessage(Message& m)
{
	if (strcmp(m.messageId, GRAPHICS_RESIZING_MESSAGE) == 0)
	{
		UnloadResourceContent();
	}
	else if (strcmp(m.messageId, GRAPHICS_RESIZED_MESSAGE) == 0)
	{
		LoadResourceContent();
	}
}

HRESULT DeferredRenderSystem::RegisterComponent(EnginePointer<IEngineComponent>& component)
{
	HRESULT hr;

	if (component->getSystemIdentifier() == getSystemIdentifier())
	{
		if (component->getComponentIdentifier() == RENDER_COMPONENT_GUID)
		{
			EnginePointer<RenderComponent> rComponent = (EnginePointer<RenderComponent>)component;
			modelComponents.push_back(rComponent);
			if (initialized)
			{
				hr = rComponent->LoadModel(pModelLoader);
				if (FAILED(hr)) return hr;
				if (models.find(rComponent->getModel()) == models.end())
				{
					models.insert(rComponent->getModel());
					hr = rComponent->getModel()->LoadGraphicsContent(pDevice);
					if (FAILED(hr)) return hr;
				}
			}
		}
		else if (component->getComponentIdentifier() == GUI_COMPONENT_GUID)
		{
			EnginePointer<GUIComponent> guiComponent = (EnginePointer<GUIComponent>)component;
			guiComponents.push_back(guiComponent);

			if (initialized)
			{
				guiComponent->LoadGraphicsContent(pDevice);
			}
		}
	}

	return S_OK;
}

GUID DeferredRenderSystem::getSystemIdentifier()
{
	return RENDER_SYSTEM_GUID;
}

void DeferredRenderSystem::Clean()
{
	UnloadGraphicsContent();
}

BOOL DeferredRenderSystem::IsClean()
{
	return !initialized;
}

list<GUID> DeferredRenderSystem::getDependencies()
{
	list<GUID> deps;
	deps.push_back(HARDWARE_SYSTEM_GUID);
	deps.push_back(SCENE_SYSTEM_GUID);
	return deps;
}
